<?php

/**
 * This is the model class for table "resident".
 *
 * The followings are the available columns in table 'resident':
 * @property string $name
 * @property string $matric_no
 * @property string $gender
 * @property string $classification
 * @property string $nationality
 * @property string $room
 * @property string $email_school
 * @property string $email
 * @property string $phone
 * @property string $faculty
 * @property string $active
 * @property string $AY
 *
 * The followings are the available model relations:
 * @property CcaResident[] $ccaResidents
 */
class Resident extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Resident the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'resident';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, matric_no, gender, classification, nationality, room, email_school, email, faculty', 'required'),
			array('name, nationality, email_school, email', 'length', 'max'=>125),
			array('matric_no', 'length', 'max'=>12),
			array('classification', 'length', 'max'=>100),
			array('gender', 'length', 'max'=>6),
			array('room', 'length', 'max'=>8),
			array('phone, faculty', 'length', 'max'=>45),
			array('active', 'length', 'max'=>20),
			array('AY', 'length', 'max'=>7),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, matric_no, password, gender, classification, nationality, room, email_school, email, phone, faculty, active, AY', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'ccaResidents' => array(self::HAS_MANY, 'CcaResident', 'matric_no'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'name' => 'Name',
			'matric_no' => 'Matric No',
			'gender' => 'Gender',
			'classification' => 'Classification',
			'nationality' => 'Nationality',
			'room' => 'Room',
			'email_school' => 'School Email',
			'email' => 'Personal Email',
			'phone' => 'Phone',
			'faculty' => 'Faculty',
			'active' => 'Active',
			'AY' => 'AY',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('name',$this->name,true);
		$criteria->compare('matric_no',$this->matric_no,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('classification',$this->classification,true);
		$criteria->compare('nationality',$this->nationality,true);
		$criteria->compare('room',$this->room,true);
		$criteria->compare('email_school',$this->email_school,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('faculty',$this->faculty,true);
		$criteria->compare('active',$this->active,true);
		$criteria->compare('AY',$this->AY,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}